package com.pagemodel.doservice;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ServletDemo
 */


/**
* 注解WebServlet用来描述一个Servlet
* 属性name描述Servlet的名字,可选
* 属性urlPatterns定义访问的URL,或者使用属性value定义访问的URL.(定义访问的URL是必选属性)
*/

/*
@WebServlet有很多的属性(Servlet3.0支持使用注解配置Servlet,不需要再在web.xml文件中进行配置)：
asyncSupported：声明Servlet是否支持异步操作模式。(true or false(default))
description：Servlet的描述。
displayName  Servlet的显示名称。
initParams：   Servlet的init参数。 例如：initParams = { @WebInitParam(name = "username", value = "张三") }//初始化参数 
name：　　　　   Servlet的名称。
urlPatterns： Servlet的访问URL。缺省Servlet用于处理所有其他Servlet都不处理的访问请求
value：　　　     Servlet的访问URL。
*/

//@WebServlet("/ServletDemo") //方法①
//@WebServlet(name="AnnotationServlet",urlPatterns={"/ServletDemo2"}) //方法②
@WebServlet(name="AnnotationServlet",value={"/ServletDemo4","/ServletDemo6","/ServletDemo8"},asyncSupported=false) //方法③
public class ServletDemo extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private static int i=0;
    /**
     * Default constructor. 
     */
    public ServletDemo() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		i++;
		response.setHeader("content-type","text/html;charset=UTF-8");//防止乱码
		response.setCharacterEncoding("UTF-8"); //防止乱码
		PrintWriter pw = response.getWriter();
		pw.print("ヾ(｡｀Д´｡)尼玛\n");
		response.getWriter().append(i+"访问的servlet 路径位于").append(request.getContextPath());
		pw.flush();
		 String username = request.getParameter("usename");
         String pwd = request.getParameter("pwd");
		request.getRequestDispatcher("/index.jsp").forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
